import React from "react";
import {INavigator} from "../NavigatorTypes";
import NavigatorConfig from "../NavigatorConfig";
import {NavigationParams, NavigationScreenProp} from "react-navigation";



export default class NativeNavigator implements INavigator {
    private rootNavigation:NavigationScreenProp<any, any> | undefined;
    private currentNavigation:NavigationScreenProp<any, any> | undefined;
    private config: NavigatorConfig | undefined;


    setRootNavigator(navigator:NavigationScreenProp<any, any>){
        this.rootNavigation = navigator;
    }
    getRootNavigator():NavigationScreenProp<any, any> | undefined{
        return this.rootNavigation;
    }
    setCurrentNavigator(navigator:any){
        this.currentNavigation = navigator;
    }
    getCurrentNavigator():NavigationScreenProp<any, any> | undefined{
        return this.currentNavigation;
    }
    private getNavigator():NavigationScreenProp<any, any> | undefined{
        // return this.currentNavigation ? this.currentNavigation : this.rootNavigation;
        return this.rootNavigation;
    }

    pop: (cb?: () => void) => void = (cb?: () => void)=>{
        this.getNavigator()!.pop();
        if(cb){
            cb();
        }
    };
    popToRoot: () => void = () => {
        this.getNavigator()!.popToTop();
    };


    push: (routeKey: string, paramsKV?:any) => void = (routeKey: string, paramsKV?:any) =>{
        this.getNavigator()!.push(routeKey, paramsKV as NavigationParams);
    };



    public initConfig(
        root: React.Component<any, any> | any,
        containID: string,
        config: NavigatorConfig,
        viewConfigs:any
    ) {
        this.config = config;
        const {StackNavigator} = require('react-navigation');
        return StackNavigator(viewConfigs);
    }


}
